<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"><meta name="referrer" content="no-referrer" />
    <title>公告页面</title>
    <script src="js/jquery-1.11.0.min.js"></script>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/materialdesignicons.min.css" rel="stylesheet">
    <link href="css/style.min.css" rel="stylesheet">
    <style>
        .left-side {
            position: fixed;
            top: 0;
            bottom: 0;
            z-index: 5;
            display: block;
            width: 240px;
            font-weight: 500;
        }

        .submenu > ul {
            display: none;
        }

        .open > ul {
            display: block;
        }
    </style>
    <script>
        $(function () {
            console.log("进入头部");
            $(".header").load("adminHeadHtml");
            console.log("展示公告！");
            $.post("/getUserName", function (obj) {
                $.ajax({
                    url: "/getNotices",
                    type: "POST",
                    success: function (result) {
                        console.log("---------");
                        console.log(result);
                        console.log("---------");
                        if (result != null) {
                            $imgs = $(".card");
                            var li = '';
                            for (let i = 0; i < result.length; i++) {
                                li = li + '<div id="contentCon" style="margin: 0 auto;height: fit-content">\n' +
                                    '                                <p id="title" style="font-size: 30px">&nbsp;&nbsp;&nbsp;>>' + result[i].title + '</p>\n' +
                                    '                                <p id="content">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + result[i].con + '</p>\n' +
                                    '                                <p id="date" style="float: right">' + result[i].date + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</br>' +
                                    '<button style="width: 80px" onclick="editNotice(' + result[i].id + ')">编辑</button><button style="width: 80px" onclick="deleteNotice(' + result[i].id + ')">删除</button></p></br></br></br>\n' +
                                    '                            </div>'
                            }
                            li = li + '<a href="addNoticeHtml"><input style="width: 160px;float: right;" class="button" value="添加" type="button"></a>';
                            $imgs.html(li);
                        }
                    }
                })
            }, "json");
        });

        function deleteNotice(a) {
            if (confirm("确认删除该公告吗？")) {
                console.log("进入删除公告方法");
                var id = a;
                console.log("---------");
                console.log(id);
                console.log("---------");
                $.ajax({
                    url: "/deleteNotice",
                    type: "POST",
                    data: JSON.stringify({"id": id}),
                    contentType: "application/json",
                    dataType: "json",
                    success: function (result) {
                        console.log("删除成功！");
                    }
                });
            }
            location.reload(true);
        }

        function editNotice(a) {
            var id = a;
            console.log("编号为：" + id);
            window.sessionStorage.setItem("id", id);
            location.href = "toEditNotice";
        }
    </script>
    <script>
        $(function () {
            $('.submenu').mouseover(function () {
                $(this).addClass('open');
            }).mouseout(function () {
                $(this).removeClass('open');
            });
        })
    </script>
</head>
<body>
<div class="lyear-layout-web">
    <div class="lyear-layout-container">
        <!--左侧导航-->
        <aside class="lyear-layout-sidebar">
            <!-- logo -->
            <div id="logo" class="sidebar-header">
                <h1 style="text-align: center;color: #33cabb;">Spider</h1>
            </div>
            <div class="lyear-layout-sidebar-scroll">
                <nav class="sidebar-main">
                    <ul class="nav nav-drawer" style="list-style: none">
                        <li class="nav-item active"><a href="/adminNotice"><i class="mdi mdi-home"></i>公告管理</a></li>
                        <li class="nav-item active"><a href="/toFindAllUsers"><i class="mdi mdi-home"></i>用户管理</a></li>
                        <li class="nav-item active"><a href="/adminComment"><i class="mdi mdi-home"></i>查看反馈</a></li>
                        <li class="nav-item active submenu"><a href="#"><i class="mdi mdi-home"></i>个人中心</a>
                            <ul class="nav nav-drawer">
                                <li class="nav-item active"><a href="/toSelf">&nbsp&nbsp&nbsp&nbsp<i
                                        class="mdi mdi-step-forward"></i>信息编辑</a></li>
                            </ul>
                        </li>
                    </ul>
                </nav>
            </div>
        </aside>
        <!--End 左侧导航-->
        <!--头部信息-->
        <div class="header"></div>
        <!--End 头部信息-->
        <!-- 主题内容 -->
        <!--页面主要内容 table table-striped table-hover-->
        <main class="lyear-layout-content">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-lg-12">
                        <div class="card">

                        </div>
                    </div>
                </div>
            </div>
        </main>
        <!--End 页面主要内容-->
    </div>
</div>
</body>
</html>